﻿@using MovieList.Helpers.Main;
@using System.Collections;
@using System.Data.SqlClient;
@model MovieList.Models.Admin.AdminIndexArray

@{
    ViewBag.Title = "Index";
}

<script type="text/javascript">

    function UpdateDirectory(Type) {

        var returnJson =
        {
            "Name": Type,
            "MediaDirectory": document.getElementById(Type).value
        };

        $.ajax({
            url: '@Url.Content("~/Admin/UpdateDirectories")',
            type: 'POST',
            dataType: 'json',
            data: JSON.stringify(returnJson),
            contentType: 'application/json; charset=utf-8',
            success: function (data) {
                if (data.Check == "0") {
                    alert("fail");
                    return;
                }
                if (data.Check == "1") {
                    alert("Success");
                    return;
                }
            }
        });
    }

</script>

<h2>Admin Index</h2>

<!-- the tabs -->
<ul class="tabs">
	<li><a href="#">Menu</a></li>
	<li><a href="#">Users</a></li>
    <li><a href="#">Media</a></li>
</ul>

<!-- tab "panes" -->
<div class="panes">
	<div>
        <h2>Menus</h2>
        <table id="rounded-corner" >
        <thead>
            <tr>
                <th class="rounded-first">
                    Id
                </th>
                <th>
                    Menu Text
                </th>
                <th>
                    Page Name
                </th>
                <th>
                    Controller Name
                </th>
                <th>
                    IsActive
                </th>
                <th class="rounded-last">
                    User Level
                </th>
            </tr>
            </thead>
            @foreach (var menu in Model.Menus)
            {
            <tr>
                <td>@menu.Id</td>
                <td>@menu.MenuText</td>
                <td>@menu.PageName</td>
                <td>@menu.ControllerName</td>
                <td>@menu.IsActive</td>
                <td>@menu.RoleId</td>
            </tr>
            }
            <tfoot>
                <tr>
                    <td class="rounded-foot-left"></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td class="rounded-foot-right"></td>
                </tr>
            </tfoot>  
        </table>
    </div>
	<div>
        <h2>Users</h2>
        <table id="rounded-corner" style="width: 100%">
            <thead>
                <tr>
                    <th class="rounded-first">UserName</th>
                    <th>Is Approved</th>
                    <th>Is Locked Out</th>
                    <th>Is Online</th>
                    <th>Email</th>
                    <th>Last Password Changed Date</th>
                    <th>Last Activity</th>
                    <th class="rounded-last">Creation Date</th>
                </tr>
            </thead>
            @foreach (MembershipUser user in Membership.GetAllUsers())
            {
                <tr>
                    <td>
                        @user.UserName
                    </td>
                    <td>
                        @user.IsApproved
                    </td>
                    <td>
                        @user.IsLockedOut
                    </td>
                    <td>
                        @user.IsOnline
                    </td>

                    <td>
                        @user.Email
                    </td>
                    <td>
                        @user.LastPasswordChangedDate
                    </td>
                    <td>
                        @user.LastActivityDate
                    </td>
                    <td>
                        @user.CreationDate
                    </td>
                </tr>
            }
            <tfoot>
                <tr>
                    <td class="rounded-foot-left"></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td class="rounded-foot-right"></td>
                </tr>
            </tfoot>  
        </table>
    </div>
	<div>
        <h2>Movies</h2>

            <label><b>Total Movies:</b></label>
            @Model.TotalMovieCount

            <br />

            <label><b>Total Tv Shows:</b></label>
            @Model.TotalTvCount

            <br />
            <br />
            <table>
                <thead>
                    <tr>
                        <th>
                            Name
                        </th>
                        <th>
                            Directory
                        </th>
                    </tr>
                </thead>
                <tbody>
                @foreach (var dir in GetDirectory.All().Directories)
                {
                    <tr>
                        <td><b>@dir.Name Directory:</b></td>
                        <td><input style="width: 350px;" id="@dir.Name" type="text" style="width:260px;" value="@dir.MediaDirectory"/></td>
                        <td><input type="button" value="Submit" onclick="UpdateDirectory('@dir.Name');" /></td>
                    </tr>
                }
                </tbody>
            </table>
            
            @Ajax.ActionLink("Test", "UpdateAll",  new AjaxOptions())
    </div>
</div>


<!-- This JavaScript snippet activates those tabs -->
<script>
    // perform JavaScript after the document is scriptable.
    $(function () {
        // setup ul.tabs to work as tabs for each div directly under div.panes
        $("ul.tabs").tabs("div.panes > div");
    });
</script>